/************************************************************************
 * The code is owned by mainframer.cn and Shang Tao
 * Without aproval of mainframer.cn and Shang Tao, removing the copyright
 * infomation is regarded as invassion of proprietary copyright
 ***********************************************************************/
package com.mr.qa;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class UserSession implements Serializable 
{
    static final long serialVersionUID = -2805284943658356093L;
    private Integer userId;
    private String loginName;
    private String type;
    private String state;
    private String name;
    private String signature;
    private String email;
    private String mobile;
    private Date registerDate;
    private boolean created = false;
    private boolean isSuper = false;
    private int score;
    private int money;
    
    private String permissions = "";
    
    private Set votedQuestions = new HashSet();
    
    private int newMessageSize;//2008.8.20
    
    private boolean adminPasswordInput = false;
    
    private boolean isActive = false;
    
    public UserSession()
    {
        
    }
    
    public UserSession(Integer userId, String loginName,String type, String state)
    {
	if (!created)
        {
            this.userId = userId;
            this.loginName = loginName;
            this.type = type;
            this.state = state;
            created = true;
	}
    }
    public boolean getCreated() 
    {
	return created;
    }

    public String getLoginName() 
    {
	return loginName;
    }

    public String getState() 
    {
	return state;
    }
    public String getType() 
    {
	return type;
    }

    public Integer getUserId()
    {
	return userId;
    }

    public void setUserId(Integer userId)
    {
        this.userId = userId;
    }
        
    public void setLoginName(String loginName)
    {
        this.loginName = loginName;
    }
        
    public void setType(String type)
    {
        this.type = type;
    }
        
    public void setState(String state)
    {
        this.state = state;
    }
        
    public void setCreated(boolean created)
    {
        this.created = created;
    }

    public void setName(String name)
    {
        this.name = name;
    }
        
    public String getName()
    {
        return name;
    }
        
    public void setSignature(String signature)
    {
        this.signature = signature;
    }
        
    public String getSignature()
    {
        return signature;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }
        
    public String getEmail()
    {
        return email;
    }
        
    public void setMobile(String mobile)
    {
        this.mobile = mobile;
    }
        
    public String getMobile()
    {
        return mobile;
    }
    
    public void addVotedQuestion(Integer questionId)
    {
        if(!this.votedQuestions.contains(questionId))
        {
            if(this.votedQuestions.size() > 100)//size over 100, one is removed randomly
            {
                Iterator ite = this.votedQuestions.iterator();
                if(ite.hasNext())
                {
                    Object obj = ite.next();
                    this.votedQuestions.remove(obj);
                }
            }
            this.votedQuestions.add(questionId);
        }
    }
    
    public boolean questionIsVoted(Integer questionId)
    {
        return this.votedQuestions.contains(questionId);
    }

    public void setScore(int score)
    {
        this.score = score;
    }
    
    public int getScore()
    {
        return score;
    }
    
    public int getMoney() {
		return money;
	}

	public void setMoney(int money) {
		this.money = money;
	}

	public void setIsSuper(boolean isSuper)
    {
        this.isSuper = isSuper;
    }
    
    public boolean getIsSuper()
    {
        return isSuper;
    }

    public void setPermissions(String permissions)
    {
        this.permissions = permissions;
    }
    
    public String getPermissions()
    {
        return permissions;
    }

    public void setRegisterDate(Date registerDate)
    {
        this.registerDate = registerDate;
    }
    
    public Date getRegisterDate()
    {
        return registerDate;
    }

    public void setNewMessageSize(int newMessageSize)
    {
        this.newMessageSize = newMessageSize;
    }
    
    public int getNewMessageSize()
    {
        return newMessageSize;
    }
    
    public boolean isAdminPasswordInput() {
		return adminPasswordInput;
	}

	public void setAdminPasswordInput(boolean adminPasswordInput) {
		this.adminPasswordInput = adminPasswordInput;
	}

	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	public String toString() 
    {
        return "id="+this.getUserId()+",login name="+this.loginName
        +",type="+this.type+",isSuper="+this.getIsSuper()+",permissions="
        +this.getPermissions();    
    }
}
